const express = require('express');
const router = express.Router();
const data = [];
router.get('/forLockedFee', async(req, res, next) => {
    const options = {
        dealerId: req.query.dealerId
    };
    const data = {
        message: 'message',
        payload: {
            lockedFee: null
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.dealerId 总代Id
 * @param {} options.brandId 品牌Id
 * @param {} options.code 编号
 * @param {} options.partSaleOrderCode 备件销售订单编号
 * @param {} options.priceTerms 价格条款  1-FOB  2-CFR  3-CIF  4-FCA  5-CPT  6-CIP  7-EXW
 * @param {} options.paymentType 付款方式  1-T/T  2-L/C  3-Credit
 * @param {} options.shipmentType 运输方式  1-海运  2-空运  3-快递
 * @param {} options.beginInvoicedDate 开票日期-开始时间
 * @param {} options.endInvoicedDate 开票日期-结束时间
 * @param {} options.pageSize 每页数据量
 * @param {} options.pageIndex 指定页
 * @param {} options.sortField 排序字段
 * @param {} options.isDesc 倒序排列
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forManage', async(req, res, next) => {
    const options = {
        dealerId: req.query.dealerId,
        brandId: req.query.brandId,
        code: req.query.code,
        partSaleOrderCode: req.query.partSaleOrderCode,
        priceTerms: req.query.priceTerms,
        paymentType: req.query.paymentType,
        shipmentType: req.query.shipmentType,
        beginInvoicedDate: req.query.beginInvoicedDate,
        endInvoicedDate: req.query.endInvoicedDate,
        pageSize: req.query.pageSize,
        pageIndex: req.query.pageIndex,
        sortField: req.query.sortField,
        isDesc: req.query.isDesc
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id621',
                    code: 'code622',
                    dealerCode: 'dealerCode623',
                    partSaleOrderCodes: 'partSaleOrderCodes',
                    shipmentType: 1,
                    paymentType: 1,
                    priceTerms: 1,
                    totalQuantity: 1,
                    totalAmount: 1,
                    totalDiscount: 1,
                    invoiceAmount: 1,
                    status: 1,
                    invoicedDate: '2019-09-10T09:00:14Z',
                    createTime: '2019-09-10T09:00:14Z',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'abandon',
                        'uploadSAP',
                    ]
                },
                {
                    id: 'id624',
                    code: 'code625',
                    dealerCode: 'dealerCode626',
                    partSaleOrderCodes: 'partSaleOrderCodes',
                    shipmentType: 1,
                    paymentType: 1,
                    priceTerms: 1,
                    totalQuantity: 1,
                    totalAmount: 1,
                    totalDiscount: 1,
                    invoiceAmount: 1,
                    status: 1,
                    invoicedDate: '2019-09-10T09:00:14Z',
                    createTime: '2019-09-10T09:00:14Z',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'abandon',
                        'uploadSAP',
                    ]
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @throws {Error}
 * @return {Promise}
 */
router.post('/forManage', async(req, res, next) => {
    const options = {
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id id
 * @throws {Error}
 * @return {Promise}
 */

router.get('/:id/forManage', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const details = Array.from({length: 99}).map((i, v) => ({
        packingListId: `packingListId${v + 1}`,
        packingListCode: `packingListCode${v + 1}`,
        partSaleOrderCode: `partSaleOrderCode${v + 1}`,
        palletCode: `palletCode${v + 1}`,
        partCode: `partCode${v + 1}`,
        partName: `partName${v + 1}`,
        quantity: 1,
        price: 1,
        pricingDate: '2019-09-10T09:00:14Z',
        totalAmount: 1,
        perNetWeight: 1,
        netWeight: 1,
        perGrossWeight: 1,
        grossWeight: 1,
        oldPartCode: `oldPartCode${v + 1}`,
        oldPartName: `oldPartName${v + 1}`,
        discountPrice: 1,
        discountAmount: 1
    }));
    const packingLists = Array.from({length: 99}).map((i, v) => ({
        id: `id${(v * 100) + 1}`,
        code: `code${(v * 100) + 1}`,
        packingType: 1,
        container: 'container',
        length: 1,
        width: 1,
        height: 1,
        volume: 1,
        netWeight: 1,
        grossWeight: 1,
        containerNo: 'containerNo',
        remark: 'remark',
        rowVersion: 'rowVersion',
        pickingListCodes: 'pickingListCodes'
    }));

    const data = {
        message: 'message',
        payload: {
            rowVersion: 'rowVersion',
            options: [
                'update',
                'abandon',
                'uploadSAP',
            ],
            id: 'id627',
            code: 'code628',
            brandCode: 'brandCode629',
            brandName: 'brandName630',
            dealerCode: 'dealerCode631',
            receiverCode: 'receiverCode632',
            country: 'country',
            currency: 1,
            buyer: 'buyer',
            buyerAddress: 'buyerAddress',
            buyerNumber: 'buyerNumber',
            buyerFAX: 'buyerFAX',
            buyerCantact: 'buyerCantact',
            seller: 'seller',
            sellerAddress: 'sellerAddress',
            sellerNumber: 'sellerNumber',
            sellerFAX: 'sellerFAX',
            origin: 'origin',
            destination: 'destination',
            paymentType: 1,
            priceTerms: 1,
            shipmentType: 3,
            itemCount: 1,
            totalQuantity: 1,
            totalAmount: 1,
            freight: 1,
            insurance: 1,
            discountAmount: 1,
            otherAmount: 1,
            claimAmount: 1,
            differentAmount: 1,
            isBonus: true,
            totalDiscount: 1,
            bonusAmount: 1,
            invoiceAmount: 1,
            discountReason: 'discountReason',
            invoicedDate: '2019-09-10T09:00:14Z',
            carrierId: '1',
            expressCompany: '快递公司',
            packingLists,
            details
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id/forManage', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id/abandon', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id/uploadSAP', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.dealerId 总代Id
 * @param {} options.shipmentType 发运方式  1-海运  2-空运  3-快递
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forManageAdd', async(req, res, next) => {
    const options = {
        dealerId: req.query.dealerId,
        shipmentType: req.query.shipmentType
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    buyer: 'buyer',
                    buyerAddress: 'buyerAddress',
                    buyerNumber: 'buyerNumber',
                    buyerFAX: 'buyerFAX',
                    buyerCantact: 'buyerCantact',
                    origin: 'origin',
                    destination: 'destination'
                },
                {
                    buyer: 'buyer',
                    buyerAddress: 'buyerAddress',
                    buyerNumber: 'buyerNumber',
                    buyerFAX: 'buyerFAX',
                    buyerCantact: 'buyerCantact',
                    origin: 'origin',
                    destination: 'destination'
                }
            ]
        }
    };
    res.json(data);
});
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        code: `XD2019082700-${i}`,
        dealerCode: '10145',
        partSaleOrderCodes: 'XD20190827001,XD20190827002',
        priceTerms: 1,
        shipmentType: 1,
        paymentType: 1,
        invoiceAmount: 190000,
        freight: 190,
        insurance: 360,
        totalDiscount: 500,
        itemCount: 10,
        totalQuantity: 15,
        totalAmount: 1552,
        status: 1,
        invoicedDate: '2019-09-04T02:37:44.918Z',
        options: ['details']
    });
router.get('/', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: data,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

const content = [];
for(let i = 1; i < 51; i++)
    content.push({
        id: `${i}`,
        code: `XD2019082700-${i}`,
        dealerCode: '10145',
        dealerName: 'dealerName',
        brandCode: 'brandCode',
        country: '中国',
        currency: 1,
        invoiceAmount: 998,
        invoicedDate: '2019-09-04T02:37:44.918Z',
        shipmentDate: '2019-09-04T02:37:44.918Z',
        actualArrivalDate: '2019-09-04T02:37:44.918Z',
        shipmentType: 3,
        origin: 'origin-string',
        destination: 'destination-string',
        rowVersion: 'string',
        details: [
            {
                id: '1',
                packingListCode: 'ZX20190908001',
                partSaleOrderCode: 'XS20190908001',
                shipmentDate: 10,
                currency: 1,
                partId: 'partId1',
                partCode: 'partCode1',
                partName: 'partName1',
                quantity: 9,
                price: 998,
                totalAmount: 1998
            }, {
                id: '2',
                packingListCode: 'ZX20190908002',
                partSaleOrderCode: 'XS20190908002',
                shipmentDate: 10,
                currency: 1,
                partId: 'partId2',
                partCode: 'partCode2',
                partName: 'partName2',
                quantity: 9,
                price: 998,
                totalAmount: 1998
            }
        ]
    });
router.get('/forShipmentConfirm', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
router.get('/forPartClaim', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
const contentDetail = [];
for(let i = 1; i < 5; i++)
    contentDetail.push({
        id: `${i}`,
        packingListCode: 'ZX20190908001',
        partSaleOrderCode: 'XS20190908001',
        partId: `${i}`,
        partCode: `partCode${i}`,
        partName: `partName${i}`,
        quantity: 9,
        price: 998
    });
router.get('/forPartClaimDetail', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: contentDetail,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
router.post('/', (req, res) => {
    res.json({
        message: '要单成功'
    });
});

router.get('/:id', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            sapOrderCode: 'SAP2019082700-1',
            sapDeliveryCode: 'SAP2019082700-2',
            currency: 1,
            invoiceCurrency: 2,
            cost: 56852,
            invoiceCode: 'FP2019090400-1',
            invoiceAmount: 999000,
            details: [
                {
                    partId: '1',
                    partCode: 'partCode1',
                    partName: 'partName1',
                    quantity: 3,
                    cif: 4,
                    discountFee: 5,
                    bonusFee: 6,
                    claimFee: 7,
                    declarationDiffFee: 8,
                    otherFee: 9,
                    exchangeDiffFee: 10,
                    rebateFee: 11,
                    cost: 12
                },
                {
                    partId: '2',
                    partCode: 'partCode2',
                    partName: 'partName2',
                    quantity: 3,
                    cif: 4,
                    discountFee: 5,
                    bonusFee: 6,
                    claimFee: 7,
                    declarationDiffFee: 8,
                    otherFee: 9,
                    exchangeDiffFee: 10,
                    rebateFee: 11,
                    cost: 12
                },
                {
                    partId: '3',
                    partCode: 'partCode3',
                    partName: 'partName3',
                    quantity: 3,
                    cif: 4,
                    discountFee: 5,
                    bonusFee: 6,
                    claimFee: 7,
                    declarationDiffFee: 8,
                    otherFee: 9,
                    exchangeDiffFee: 10,
                    rebateFee: 11,
                    cost: 12
                }
            ]
        }
    });
});

router.get('/forHistory/forCurrentUser', async(req, res, next) => {
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: '1',
                    code: 'code622',
                    dealerCode: 'dealerCode623',
                    dealerName: 'dealerName54',
                    partIvoiceNumber: 3214,
                    currency: 1,
                    invoiceAmount: 3145,
                    freight: 13,
                    insurance: 321,
                    invoicedDate: '2019-11-16T02:49:39.611Z',
                    status: 16101001,
                    orderCodes: 'orderCodes531',
                    preReceiptDate: '2019-11-16T02:50:40.366Z',
                    dataSendDate: '2019-09-10T09:00:14Z',
                    shipmentType: 15961001,
                    toPortDate: '2019-11-16T02:50:40.367Z',
                    rowVersion: 'rowVersion',
                },
                {
                    id: '2',
                    code: 'code622',
                    dealerCode: 'dealerCode623',
                    dealerName: 'dealerName54',
                    partIvoiceNumber: 3214,
                    currency: 1,
                    invoiceAmount: 3145,
                    freight: 13,
                    insurance: 321,
                    invoicedDate: '2019-11-16T02:49:39.611Z',
                    status: 16101004,
                    orderCodes: 'orderCodes531',
                    preReceiptDate: '2019-11-16T02:50:40.366Z',
                    dataSendDate: '2019-09-10T09:00:14Z',
                    shipmentType: 15961002,
                    toPortDate: '2019-11-16T02:50:40.367Z',
                    rowVersion: 'rowVersion',
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});

router.get('/:id/forHistory', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message',
        payload: {
            rowVersion: 'rowVersion',
            id: '1',
            buyer: 'buyer',
            code: 'code',
            buyerAddress: 'buyerAddress',
            invoicedDate: '2019-11-16T04:03:39.672Z',
            buyerNumber: 'buyerNumber',
            orderCodes: 'orderCodes',
            buyerFAX: 'buyerFAX',
            preReceiptDate: '2019-11-16T04:03:39.672Z',
            buyerCantact: 'buyerCantact',
            seller: 'seller',
            sellerAddress: 'sellerAddress',
            sellerNumber: 'sellerNumber',
            sellerFAX: 'sellerFAX',
            fromPort: 'fromPort',
            destinationPort: 'destinationPort',
            paymentHisType: 1,
            priceTerms: 1,
            shipmentType: 15961001,
            partInvoiceDetails: [
                {
                    partId: '1',
                    partCode: 'partCode1',
                    partName: 'partName1',
                    partEngName: 'partEngName1',
                    quantity: 123,
                    unitPrice: 250,
                    totalAmount: 456456,
                    packageCode: 'packageCode1',
                    perNetWeight: 123.12,
                    netWeight: 23.32,
                    oldPartCode: 'oldPartCode1',
                    orderCode: 'orderCode1',
                },
                {   
                    partId: '2',
                    partCode: 'partCode2',
                    partName: 'partName2',
                    partEngName: 'partEngName2',
                    quantity: 123,
                    unitPrice: 250,
                    totalAmount: 456456,
                    packageCode: 'packageCode2',
                    perNetWeight: 123.12,
                    netWeight: 23.32,
                    oldPartCode: 'oldPartCode2',
                    orderCode: 'orderCode2',
                }
            ],
            partInvoicePackages: [
                {
                    packageId: '1',
                    packageType: 16031001,
                    packageCode: 'packageCode1',
                    containerCode: 'containerCode1',
                    packageLength: 23.21,
                    packageWidth: 45.75,
                    packageHeight: 41.83,
                    packageVolume: 4645.21,
                    netWeight: 844.13,
                    grossWeight: 913.12
                },
                {
                    packageId: '2',
                    packageType: 16031001,
                    packageCode: 'packageCode1',
                    containerCode: 'containerCode1',
                    packageLength: 23.21,
                    packageWidth: 45.75,
                    packageHeight: 41.83,
                    packageVolume: 4645.21,
                    netWeight: 844.13,
                    grossWeight: 913.12
                }
            ]
        }
    };
    res.json(data);
});
router.get('/:id/ExportPartClaimDetail', (req, res) => {
    res.json({
        message: '导出成功',
        payload: 'Mock导出'
    });
});
module.exports = router;
